package com.correction.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.correction.classes.Utilisateur;
import com.correction.classes.Utilisateur.Niveau;
import com.correction.service.UtilisateurDAO;

public class GetStudentList extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		try {
			Niveau niveau = Niveau.valueOf(request.getParameter("niv"));
			List<Utilisateur> studentList = UtilisateurDAO.getEtudiants(niveau);
			String data = "<option value=''></option>";
			for (Utilisateur utilisateur : studentList) {
				int value = utilisateur.getIdUtilisateur();
				String name = utilisateur.getNom() + ","
						+ utilisateur.getPrenom();
				data += "<option value='" + value + "'>" + name + "</option>";
			}
			out.print(data);
		} catch (Exception ex) {
			out.print("Error getting product name..." + ex.toString());
		} finally {
			out.close();
		}
	}
}
